var $ = require('../../utils/Ajax.js');
Page({
  data: {
    // 图片地址
    PictureUrl: getApp().PictureUrl,
    Msg: null,
    MsgHidden: false
  },
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: "系统消息"
    })
  },
  
  onShow: function () {
    var that = this;
    $.Ajax("api/x_mess", "GET", {}, function (res) {
      if (res.d.message.length != 0){
        that.setData({
          MsgHidden: true
        })
      }else{
        that.setData({
          MsgHidden: false
        })
      }
      that.setData({
        Msg: res.d.message
      })
    })
  },

  // 点击系统消息 - 体验
  ExperDetails: function (e) {
    var Id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../ExperDetails/ExperDetails?Id=' + Id,
    })
  },

  // 点击系统消息 - 活动
  Activities: function (e) {
    var Id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../ActiviDetails/ActiviDetails?Id=' + Id,
    })
  },

  // 监听用户下拉刷新
  onPullDownRefresh: function () {
    
    // 手机震动
    wx.vibrateShort();

    var that = this;
    $.Ajax("api/x_mess", "GET", {}, function (res) {
      if (res.d.message.length != 0) {
        that.setData({
          MsgHidden: true
        })
      }
      that.setData({
        Msg: res.d.message
      })
      wx.stopPullDownRefresh({
        success: function (res) {
          wx.showToast({
            title: '刷新成功',
            icon: 'succes',
            duration: 2000,
            mask: true
          })
        }
      })
    })
  }
})